import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controller/remaining_timer_controller.dart';

class RemainingTimerWidget extends StatelessWidget {
  final String tag;
  final int remainingSeconds;
  final int timeoutSeconds;
  final Color color;
  final Function()? callback;

  const RemainingTimerWidget({
    required this.tag,
    required this.remainingSeconds,
    required this.timeoutSeconds,
    required this.color,
    required this.callback,
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    final timerController = Get.put(
        RemainingTimerController(
          remainingSeconds: remainingSeconds,
          timeoutSeconds: timeoutSeconds,
          callback: callback,
        ),
        tag: tag);
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 3),
      decoration: BoxDecoration(
        color: Colors.transparent, //设置背景颜色
        border: Border.all(color: color, width: 1.0, style: BorderStyle.solid), borderRadius: const BorderRadius.all(Radius.circular(3)),
      ),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Icon(Icons.watch_later, size: 11, color: color),
          SizedBox(
            width: 3,
          ),
      GetBuilder<RemainingTimerController>(
        tag: tag,
        builder:(controller) => Text(
              timerController.time.value,
              style: TextStyle(
                fontSize: 11,
                color: color,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
